﻿CREATE TABLE [invoicing2014].[BookOrderDetails] (
    [ID]         INT             IDENTITY (1, 1) NOT NULL,
    [OID]        INT             NOT NULL,
    [ProductID]  INT             NOT NULL,
    [MaterialID] INT             NOT NULL,
    [ProcessID]  INT             NOT NULL,
    [Size]       VARCHAR (50)    NOT NULL,
    [Quantity]   DECIMAL (18, 5) CONSTRAINT [DF_BookOrderDetails_Quantity] DEFAULT ((0)) NOT NULL,
    CONSTRAINT [PK_BookOrderDetails] PRIMARY KEY CLUSTERED ([ID] ASC),
    CONSTRAINT [FK_BookOrderDetails_BookOrders] FOREIGN KEY ([OID]) REFERENCES [invoicing2014].[BookOrders] ([ID]) ON DELETE CASCADE,
    CONSTRAINT [FK_BookOrderDetails_ProductMaterials] FOREIGN KEY ([MaterialID]) REFERENCES [dbo].[ProductMaterials] ([ID]),
    CONSTRAINT [FK_BookOrderDetails_ProductProcesses] FOREIGN KEY ([ProcessID]) REFERENCES [dbo].[ProductProcesses] ([ID]),
    CONSTRAINT [FK_BookOrderDetails_Products] FOREIGN KEY ([ProductID]) REFERENCES [dbo].[Products] ([ID]),
    CONSTRAINT [FK_BookOrderDetails_Products1] FOREIGN KEY ([ProductID]) REFERENCES [dbo].[Products] ([ID])
);

